#include "StdAfx.h"
#include "Graphics.h"

CScoreBoard::CScoreBoard(void)
{

}

CScoreBoard::~CScoreBoard(void)
{
	if(this->_hbmpBackground)
	{
		DeleteObject(_hbmpBackground);
	}
	if(this->_hbmpBgndFill)
	{
		DeleteObject(this->_hbmpBgndFill);
	}
}

void CScoreBoard::Initialize(CGraphics *pGraphics, HINSTANCE hInstance)
{
	this->_hbmpBackground = (HBITMAP)pGraphics->LoadBitmapFromResource(IDB_SCOREBACKGROUND, hInstance);
	this->_hbmpBgndFill = (HBITMAP)pGraphics->LoadBitmapFromResource(IDB_SCOREBOTTOMFILL, hInstance);
	this->_nScore = 0;
}

void CScoreBoard::DrawScoreBoard(CGraphics *pGraphics, RECT *pClientRect)
{
	int nAmountLeftover = pClientRect->bottom % SEGMENT_WIDTH;
	RECT rectAreaToDraw;
	rectAreaToDraw.left = 0;
	rectAreaToDraw.right = pClientRect->right;
	rectAreaToDraw.top = pClientRect->bottom - (SCOREBOARDHEIGHT + nAmountLeftover);

	// draw the main portion first
	for(int i = 0; i <= pClientRect->right / SCOREBOARDWIDTH; i++)
	{
		pGraphics->DisplayBitmap(this->_hbmpBackground, i * SCOREBOARDWIDTH, rectAreaToDraw.top);
	}

	//draw any left over portion on the bottom now
	if(nAmountLeftover > 0)
	{
		for(int i = 0; i <= pClientRect->right / SCOREBOARDWIDTH; i++)
		{
			pGraphics->DisplayBitmap(this->_hbmpBgndFill, i * SCOREBOARDWIDTH, rectAreaToDraw.top + SCOREBOARDHEIGHT);
		}

	}
	// draw the score
	//rectAreaToDraw.left += 16;
	//rectAreaToDraw.top += 32;
	wchar_t szBuff[20] = {0};
	wsprintf(szBuff, L"Score: %d", this->_nScore);
	rectAreaToDraw.bottom = rectAreaToDraw.top + SCOREBOARDHEIGHT + nAmountLeftover;
	pGraphics->DisplayText(szBuff, &rectAreaToDraw, DT_CENTER | DT_VCENTER);




}

void CScoreBoard::SetScore(int score)
{
	_nScore = score;
}

int CScoreBoard::GetScore()
{
	return _nScore;
}

RECT CScoreBoard::GetCurrentGameWindow(HWND hWnd)
{
	RECT theRect;
	GetClientRect(hWnd, &theRect);
	int nAmountLeftover = theRect.bottom % SEGMENT_WIDTH;
	theRect.bottom -= SCOREBOARDHEIGHT + nAmountLeftover;
	return theRect;
}